Developer Documentation

QuickTime 4 API Documentation

3D Graphics Programming with QuickDraw 3D 1.5.4

Previous | QD3D Book | Overview | Chapter Contents | Next |

Trimeshes

A trimesh is a collection of vertices, edges, and faces in which all faces are triangular. In other words, a trimesh is simply a mesh composed entirely of triangles. A trimesh is like a polyhedron in that its faces are defined indirectly, using indices into an array of vertices. Similarly, the edges of a trimesh are defined by an optional array of edge vertices.

The main difference between trimeshes and all other QuickDraw 3D primitives (including polyhedra) is that attributes for trimesh vertices, edges, and faces are not stored as objects of type TQ3AttributeSet ; rather, those attributes are stored in arrays of explicit attribute data structures. Moreover, if any single vertex (or edge, or face) has an attribute of a specific non-custom type, then every vertex (or edge, or face) in the trimesh must also have an attribute of that type. This restriction can deleteriously affect the memory requirements of a large trimesh.

See "Comparison of the Polyhedral Primitives" for more information on the advantages and disadvantages of using trimeshes to model a polyhedral surface.

A trimesh triangle data structure specifies information about a triangular face of a trimesh. A trimesh triangle data structure is defined by the TQ3TriMeshTriangleData data type.

typedef struct TQ3TriMeshTriangleData {
    unsigned long                       pointIndices[3];
} TQ3TriMeshTriangleData;
pointIndices
Three indices into an array of three-dimensional points. (The array is specified by the points field of the TQ3TriMeshData data structure.) These three points define the vertices of the face.

A trimesh edge data structure specifies information about an edge of a trimesh; it is defined by the TQ3TriMeshEdgeData data structure.

typedef struct TQ3TriMeshEdgeData {
    unsigned long                       pointIndices[2];
    unsigned long                       triangleIndices[2];
} TQ3TriMeshEdgeData;
pointIndices
Two indices into an array of three-dimensional points. (The array is specified by the points field of the TQ3TriMeshData data structure.) These two points define the endpoints of the edge.
triangleIndices
Two indices into an array of trimesh triangle data structures, which contain information about the faces in the trimesh. (The array is specified by the triangles field of the TQ3TriMeshData data structure.) These two triangles define the two faces that contain the edge. When an edge abuts only one face (that is, when the edge is on a boundary of the trimesh), you can use the constant kQ3ArrayIndexNULL as the face index for the side of the edge that has no face attached to it.

Attributes for the parts of a trimesh are defined by a trimesh attributes data structure, of type TQ3TriMeshAttributeData .

typedef struct TQ3TriMeshAttributeData {
    TQ3AttributeType                    attributeType;
    void                                *data;
    char                                *attributeUseArray
} TQ3TriMeshAttributeData;
attributeType
The type of the attribute.
data
A pointer to the attribute data.
attributeUseArray
A pointer to an array of 0's and 1's that defines which vertices (or edges, or faces) have custom attributes.

When the attributeType field is set to a pre-defined (that is, non-custom) attribute type, the attributeUseArray field must contain NULL . When the attributeType field is set to a custom attribute type, it should contain a pointer to an array containing only the values 0 and 1. If an element in attributeUseArray has the value 1, then the corresponding vertex (or edge, or face) has a custom attribute; otherwise, if an element in this array has the value 0, the corresponding vertex (or edge, or face) doesn't have a custom attribute.

Finally, a trimesh is defined by the TQ3TriMeshData data type.
 
typedef struct TQ3TriMeshData {
    TQ3AttributeSet                     triMeshAttributeSet;
    unsigned long                       numTriangles;
    TQ3TriMeshTriangleData              *triangles;
    unsigned long                       numTriangleAttributeTypes;
    TQ3TriMeshAttributeData             *triangleAttributeTypes;
    unsigned long                       numEdges;
    TQ3TriMeshEdgeData                  *edges;
    unsigned long                       numEdgeAttributeTypes;
    TQ3TriMeshAttributeData             *edgeAttributeTypes;
    unsigned long                       numPoints;
    TQ3Point3D                          *points;
    unsigned long                       numVertexAttributeTypes;
    TQ3TriMeshAttributeData             *vertexAttributeTypes;
    TQ3BoundingBox                      bBox;
} TQ3TriMeshData;
triMeshAttributeSet
A pointer to a trimesh attributes data structure that contains information about the attributes of the entire trimesh. If the trimesh has no attributes, this field should be set to NULL .
numTriangles
The number of triangles (that is, faces) in the trimesh.
triangles
A pointer to an array of trimesh triangle data structures, which contain information about the faces in the trimesh.
numTriangleAttributeTypes
The number of types of attributes that are associated with each triangle in the trimesh.
triangleAttributeTypes
A pointer to a trimesh attributes data structure that contains information about the face attributes of the trimesh. If no attributes are to be assigned to individual faces of the trimesh, this field should be set to NULL .
numEdges
The number of edges in the trimesh. Set this field to 0 if you do not want to specify any edges.
edges
A pointer to an array of trimesh edge data structures, which contain information about the edges in the trimesh. Set this field to NULL if you do not want to specify any edges.
numEdgeAttributeTypes
The number of types of attributes that are associated with each edge in the trimesh.
edgeAttributeTypes
A pointer to a trimesh attributes data structure that contains information about the edge attributes of the trimesh. If no attributes are to be assigned to individual edges of the trimesh, this field should be set to NULL .
numPoints
The number of points in the trimesh.
points
A pointer to the array of points in the trimesh.
numVertexAttributeTypes
The number of types of attributes that are associated with each vertex in the trimesh.
vertexAttributeTypes
A pointer to a trimesh attributes data structure that contains information about the vertex attributes of the trimesh. If no attributes are to be assigned to individual vertices of the trimesh, this field should be set to NULL .
bBox
The bounding box of the trimesh.

You can accelerate trimesh rendering by specifying the trimesh as a strip or fan. A strip is a trimesh whose triangles are ordered sequentially (that is, each triangle has one edge in common with the previous neighboring triangle, a second edge in common with the next neighboring triangle, and the remaining edge in common with no other triangle). A fan is a strip in which all the triangles share a common vertex.


© 1997 Apple Computer, Inc.

Previous | QD3D Book | Overview | Chapter Contents | Next |